//
//  YD_MyGiftStatusCell.m
//  SpeedDating
//
//  Created by isu on 16/12/26.
//  Copyright © 2016年 isu. All rights reserved.
//

#import "YD_MyGiftStatusCell.h"
#import "YD_getCurrentResponseVCTool.h"


@interface YD_MyGiftStatusCell()
/** headImageV*/
@property (nonatomic, strong)UIImageView *headImageV;
/** nickNameLab*/
@property (nonatomic, strong)UILabel *nickNameLab;
/** sexBtn*/
@property (nonatomic, strong)UIButton *sexBtn;
/** constellationBtn*/
@property (nonatomic, strong)UIButton *constellationBtn;
/** areaInfoLab*/
@property (nonatomic, strong)UILabel *areaInfoLab;
/** giftImageV*/
@property (nonatomic, strong)UIImageView *giftImageV;
/** giftDesLab*/
@property (nonatomic, strong)UILabel *giftDesLab;
/** giftPriceLab*/
@property (nonatomic, strong)UILabel *giftPriceLab;
/** timeLab*/
@property (nonatomic, strong)UILabel *timeLab;
/** giftStatusaLab*/
@property (nonatomic, strong)UILabel *giftStatusaLab;
@end


@implementation YD_MyGiftStatusCell

- (void)awakeFromNib {

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    
}
+(instancetype)cellWithTableView:(UITableView*)tableView {
    static NSString *ID = @"YD_MyGiftStatusCell";
    YD_MyGiftStatusCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell==nil){
        cell = [[YD_MyGiftStatusCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID ];
        cell.backgroundColor =[UIColor whiteColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.headImageV = [UIImageView new];
        [self.contentView addSubview:self.headImageV];
        [self.headImageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.mas_equalTo(10);
            make.size.mas_equalTo(CGSizeMake(40, 40));
        }];
        self.headImageV.image =[UIImage imageNamed:@""];
        self.headImageV.layer.cornerRadius = 20.0f;
        self.headImageV.layer.masksToBounds = YES;
        self.headImageV.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick)];
        [self.headImageV addGestureRecognizer:tap];

        self.nickNameLab = [UILabel new];
        [self.contentView addSubview:self.nickNameLab];
        [self.nickNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.headImageV.mas_top).offset(5);
            make.left.mas_equalTo(self.headImageV.mas_right).offset(5);
            make.width.mas_lessThanOrEqualTo(KScreenWidth/3.0*2-35);
            make.bottom.mas_equalTo(self.headImageV.mas_top).offset(25.0);
        }];
        self.nickNameLab.text = @"";
        self.nickNameLab.font =[UIFont systemFontOfSize:15.0f];
        
        self.sexBtn = [UIButton new];
        [self.contentView addSubview:self.sexBtn];
        [self.sexBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.nickNameLab.mas_top);
            make.left.mas_equalTo(self.nickNameLab.mas_right);
            make.bottom.mas_equalTo(self.nickNameLab.mas_bottom);
            make.width.mas_equalTo(50);
        }];
        [self.sexBtn setBackgroundImage:[UIImage imageNamed:@"nianlingnan"] forState:UIControlStateNormal];
        [self.sexBtn setImage:[UIImage imageNamed:@"male"] forState:UIControlStateNormal];
        self.sexBtn.imageEdgeInsets = UIEdgeInsetsMake(5,8,5,30);
        self.sexBtn.titleEdgeInsets = UIEdgeInsetsMake(0,-12,0,8);
        [self.sexBtn setTitle:@" " forState:UIControlStateNormal];
        [self.sexBtn.titleLabel setFont:[UIFont systemFontOfSize:12.0f]];
        self.sexBtn.userInteractionEnabled = NO;
        [self.sexBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
        self.constellationBtn = [UIButton new];
        [self.contentView addSubview:self.constellationBtn];
        [self.constellationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.nickNameLab.mas_top);
            make.left.mas_equalTo(self.sexBtn.mas_right).offset(5);
            make.bottom.mas_equalTo(self.nickNameLab.mas_bottom);
            make.width.mas_equalTo(50);
        }];
        [self.constellationBtn setBackgroundImage:[UIImage imageNamed:@"星座"] forState:UIControlStateNormal];
        [self.constellationBtn setTitle:@"" forState:UIControlStateNormal];
        [self.constellationBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.constellationBtn.titleLabel setFont:[UIFont systemFontOfSize:12.0f]];
        self.constellationBtn.userInteractionEnabled = NO;
        
        self.areaInfoLab = [UILabel new];
        [self.contentView addSubview:self.areaInfoLab];
        [self.areaInfoLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.nickNameLab.mas_bottom).offset(5);
            make.left.mas_equalTo(self.headImageV.mas_right).offset(5);
            make.right.mas_equalTo(-20);
            make.bottom.mas_equalTo(self.headImageV.mas_bottom).offset(2);
        }];
        self.areaInfoLab.text = @"";
        self.areaInfoLab.font =[UIFont systemFontOfSize:13.0f];

        UIView *giftBaseV = [UIView new];
        giftBaseV.backgroundColor=[UIColor colorWithWhite:0.902 alpha:1.000];
        [self.contentView addSubview:giftBaseV];
        [giftBaseV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.areaInfoLab.mas_bottom).offset(5);
            make.left.mas_equalTo(self.areaInfoLab.mas_left);
            make.right.mas_equalTo(-20);
            make.bottom.mas_equalTo(-10);
        }];
        giftBaseV.layer.cornerRadius = 3.0f;

        UIView *lineV = [UIView new];
        lineV.backgroundColor =[UIColor lightGrayColor];
        [self.contentView addSubview:lineV];
        [lineV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_equalTo(self.contentView);
            make.height.mas_equalTo(0.5);
        }];
  
        self.giftImageV = [UIImageView new];
        [giftBaseV addSubview:self.giftImageV];
        [self.giftImageV  mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(giftBaseV.mas_left).offset(15);
            make.top.mas_equalTo(giftBaseV.mas_top).offset(15);
            make.bottom.mas_equalTo(giftBaseV.mas_bottom).offset(-15);
            make.width.mas_equalTo(self.giftImageV.mas_height).multipliedBy(0.8                                                                                                     );
        }];
        self.giftImageV.image =[UIImage imageNamed:@""];
        
        
        UIView *centerL = [UIView new];
        [giftBaseV addSubview:centerL];
        [centerL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(giftBaseV);
            make.left.right.mas_equalTo(giftBaseV);
            make.height.mas_equalTo(0.5);
        }];
       // centerL.backgroundColor =[UIColor redColor];
    
        self.timeLab  = [UILabel new];
        [giftBaseV addSubview:self.timeLab];
        [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(centerL.mas_top).offset(-3);
            make.right.mas_equalTo(giftBaseV.mas_right).offset(-5);
        }];
        self.timeLab.text = @"";
        self.timeLab.font =[UIFont systemFontOfSize:11.0f];
        self.timeLab.textColor =[UIColor lightGrayColor];
        self.timeLab.textAlignment =NSTextAlignmentRight;
      
        self.giftDesLab = [UILabel new];
        [giftBaseV addSubview:self.giftDesLab];
        [self.giftDesLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(centerL.mas_top).offset(-3);
            make.left.mas_equalTo(self.giftImageV.mas_right).offset(5);
            make.right.mas_lessThanOrEqualTo(self.timeLab.mas_left).offset(-2);
            
        }];
        self.giftDesLab.text = @"";
        self.giftDesLab.font =[UIFont systemFontOfSize:11.0f];
        self.giftDesLab.textColor =[UIColor lightGrayColor];
        self.giftDesLab.numberOfLines = 2;
        self.giftDesLab.textAlignment = NSTextAlignmentLeft;
        
        self.giftStatusaLab  = [UILabel new];
        [giftBaseV addSubview:self.giftStatusaLab];
        [self.giftStatusaLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(centerL.mas_bottom).offset(3);
            make.right.mas_equalTo(giftBaseV.mas_right).offset(-5);
        }];
        self.giftStatusaLab.text = @"";
        self.giftStatusaLab.font =[UIFont systemFontOfSize:11.0f];
        self.giftStatusaLab.textColor =[UIColor lightGrayColor];
        self.giftStatusaLab.textAlignment =NSTextAlignmentRight;
        
        
        
        self.giftPriceLab = [UILabel new];
        [giftBaseV addSubview:self.giftPriceLab];
        [self.giftPriceLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(centerL.mas_top).offset(2);
            make.left.mas_equalTo(self.giftImageV.mas_right).offset(5);
            make.right.mas_lessThanOrEqualTo(self.giftStatusaLab.mas_left).offset(-2);
            
        }];
        self.giftPriceLab.text = @"";
        self.giftPriceLab.font =[UIFont systemFontOfSize:11.0f];
        self.giftPriceLab.textColor =[UIColor lightGrayColor];
        self.giftPriceLab.numberOfLines = 2;
        self.giftPriceLab.textAlignment = NSTextAlignmentLeft;
}
    return self;
}

-(void)setMyGiftModel:(YD_myGiftModel *)myGiftModel{
    _myGiftModel = myGiftModel;
    [self.headImageV sd_setImageWithURL:[NSURL URLWithString:HttpImgUrl(myGiftModel.photo)] placeholderImage:[UIImage imageNamed:@"llustration"]];
    if(myGiftModel.sex == 1){//femal
       [self.sexBtn setImage:[UIImage imageNamed:@"male"] forState:UIControlStateNormal];
        [self.sexBtn setBackgroundImage:[UIImage imageNamed:@"nianlingnan"] forState:UIControlStateNormal];
    }else{
        [self.sexBtn setImage:[UIImage imageNamed:@"female"] forState:UIControlStateNormal];
        [self.sexBtn setBackgroundImage:[UIImage imageNamed:@"nianlingnv"] forState:UIControlStateNormal];
    }
    [self.sexBtn setTitle:myGiftModel.age forState:UIControlStateNormal];
    [self.constellationBtn setTitle:myGiftModel.star forState:UIControlStateNormal];
    self.nickNameLab.text = myGiftModel.nickName;
    self.areaInfoLab.text = [NSString stringWithFormat:@"%@  %@km",myGiftModel.location,myGiftModel.distance];
    [self.giftImageV sd_setImageWithURL:[NSURL URLWithString:HttpImgUrl(myGiftModel.img)] placeholderImage:[UIImage imageNamed:@"llustration"]];
    self.giftDesLab.text = myGiftModel.giftName;
    self.giftPriceLab.text = [NSString stringWithFormat:@"价值: %.0ld钻石",(long)myGiftModel.charm];
    self.timeLab.text  = myGiftModel.createTime;
    switch (myGiftModel.status) {
        case 1:
            self.giftStatusaLab.text =@"已送出暂未接收";
            break;
        case 2:
            self.giftStatusaLab.text =@"已接收";
            break;
        case 3:
            self.giftStatusaLab.text =@"已过期并退回";
            break;
        default:
            break;
    }
}

-(void)tapClick{
    
//    HRUserDetailInfoViewController *vc = [HRUserDetailInfoViewController new];
//    vc.uid = self.myGiftModel.wid;
//    [[YD_getCurrentResponseVCTool getCurrentResponseVC:self].navigationController pushViewController:vc animated:YES];
    
}

@end
